package com.tanxi521.tnweb.utils;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

public class Result {

    public static final String CODE = "code";
    public static final String MSG = "msg";
    public static final String SUCCESS = "success";

    public static Map<String, Object> info(String code, String msg, String success) {
        Map<String, Object> result = new HashMap<>();
        result.put(CODE, code);
        result.put(MSG, msg);
        result.put(SUCCESS, success);
        return result;
    }

    public static Map<String, Object> success() {
        Map<String, Object> result = new HashMap<>();
        result.put(CODE, "1");
        result.put(MSG, "成功");
        result.put(SUCCESS, true);
        return result;
    }

    public static Map<String, Object> success(String msg) {
        Map<String, Object> result = new HashMap<>();
        result.put(CODE, "1");
        result.put(MSG, msg);
        result.put(SUCCESS, true);
        return result;
    }

    public static Map<String, Object> error() {
        Map<String, Object> result = new HashMap<>();
        result.put(CODE, "0");
        result.put(MSG, "失败");
        result.put(SUCCESS, false);
        return result;
    }

    public static Map<String, Object> error(String msg) {
        Map<String, Object> result = new HashMap<>();
        result.put(CODE, "0");
        result.put(MSG, msg);
        result.put(SUCCESS, false);
        return result;
    }


    public static String generateCode(int len) {
        StringBuilder stringBuilder = new StringBuilder();
        for (int j = 0; j < len; j++) {
            stringBuilder.append(new Random().nextInt(10));
        }
        return stringBuilder.toString();
    }
}
